﻿#include "FITKAbstractSEASubSys.h"
#include "FITKSEASubSysGeoProp.h"
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsPhysicsProp.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsMaterial.h"
#include "FITK_Interface/FITKInterfaceModel/FITKCoordinateSystem.h"

namespace Acoustics
{

    FITKAbstractSEASubSys::FITKAbstractSEASubSys()
    {
        //几何属性
        _geoProp = new FITKSEASubSysGeoProp(this);
        //坐标系,默认笛卡尔坐标系
        _coordinate = new Interface::FITKCoordinateSystem(Interface::FITKCoordinateSystem::FCSCartesian);
    }

    FITKAbstractSEASubSys::~FITKAbstractSEASubSys()
    {
        if (_geoProp) delete _geoProp;
        if (_coordinate) delete _coordinate;
    }
    void FITKAbstractSEASubSys::setPropSection(const int pid)
    {
        _propSection = pid;
    }

    int FITKAbstractSEASubSys::getPropSectionID()
    {
        return _propSection;
    }

    Acoustics::FITKAcousticsAbsPhysicsProp* FITKAbstractSEASubSys::getPropSectionObj()
    {
        //从数据仓库及获取
        if (_propSection <= 0) return  nullptr; 
        return FITKDATAREPO->getTDataByID<FITKAcousticsAbsPhysicsProp>(_propSection);
    }

    void FITKAbstractSEASubSys::setMaterialID(const int matID)
    {
        _materialID = matID;
    }

    int FITKAbstractSEASubSys::getMaterialID() const
    {
        return _materialID;
    }

    FITKAcousticsAbsMaterial* FITKAbstractSEASubSys::getAcousticsMaterial()
    {
        if (_materialID <= 0) return nullptr;
        return FITKDATAREPO->getTDataByID<FITKAcousticsAbsMaterial>(_materialID);

    }


    bool FITKAbstractSEASubSys::updateGeoProp()
    {
        if (_geoProp == nullptr) return false;
        //重新计算
        bool OK = _geoProp->updateProp();
        
        OK &= this->updateCoordinate();
        return OK;
    }

    Acoustics::FITKSEASubSysGeoProp* FITKAbstractSEASubSys::getGeoProp()
    {
        //几何属性
        return _geoProp;
    }

    Interface::FITKCoordinateSystem* FITKAbstractSEASubSys::getCoordinateSys()
    {
        return _coordinate;
    }
 
    bool FITKAbstractSEASubSys::isContainsNode(const int id) const
    {
        return false;
    }

    bool FITKAbstractSEASubSys::updateCoordinate()
    {
        return false;
    }

    FITKAbstractSEASubSys::SEASubSysType FITKAbstractSEASubSys::getSEASubSysType()
    {
        //错误值
        return FITKAbstractSEASubSys::SEASubSysType::SEASSNone;
    }

    QList<int> FITKAbstractSEASubSys::getNodeIDs() const
    {
        return QList<int>();
    }

 
   

    QList<int> FITKAbstractSEASubSys::getTriangleNodeIDs()
    {
        return this->getNodeIDs();
    }

    QList<FITKAbstractSEASubSys*> FITKAcousticsSEASubSysManager::getSubSysByType(
        FITKAbstractSEASubSys::SEASubSysType type)
    {
        QList<FITKAbstractSEASubSys*> subsys;
        //遍历全部对象
        const int n = this->getDataCount();
        for (int i = 0 ; i < n; ++i)
        {
            FITKAbstractSEASubSys* sys = this->getDataByIndex(i);
            if(sys == nullptr) continue;
            //类型判断
            if (sys->getSEASubSysType() == type)
                subsys.append(sys);
        }
        return subsys;
    }

}


